/**
 * 
 */
package com.gi.profiler.views;

import android.app.AlertDialog;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.gi.profiler.R;
import com.gi.profiler.providers.IconsAdapter;

/**
 * @author Ruba Used in Profile View Screen.
 * 
 */
public class IconGridDialog extends DialogPreference {

    private Context prefsActivity;

    public IconGridDialog(Context prefsActivity, AttributeSet attrs) {
	super(prefsActivity, attrs);
	this.prefsActivity = prefsActivity;

	setDialogLayoutResource(R.layout.icons_grid);
    }

    /**
     * Hide dialog default title or buttons inside onPrepareDialogBuilder:
     */
    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
	builder.setTitle(R.string.title_icon_chooser);
	builder.setPositiveButton(null, null);
	super.onPrepareDialogBuilder(builder);
    }

    
    /**
     * To gain control over your view elements find them in onBindDialogView:
     */
    @Override
    public void onBindDialogView(View view) {
	
	GridView gridview = (GridView) view.findViewById(R.id.icons_gridview);
	gridview.setAdapter(new IconsAdapter(prefsActivity));

	gridview.setOnItemClickListener(new OnItemClickListener() {
	    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		// Toast.makeText(HelloGridView.this, "" + position,
		// Toast.LENGTH_SHORT).show();
	    }
	});
	
	super.onBindDialogView(view);
    }

}
